/*
 * TreeTab.java
 *
 * Created on November 5, 2009, 4:09 AM
 * 10, Feb. 2014, Trivial modifications were made to make the code compatible with Java 1.7
 */

package portfolio.dbHost;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import portfolio.mainScreen;

/**
 *
 * @author  ACA
 */
public abstract class TreeTab implements MouseListener {
    protected mainScreen mainFrame  = null;
    protected Object     treeObject = null;
    
    protected JTree visibleTree     = null;
    
    /**
     *
     * @param e 
     */
    public void mouseClicked  (MouseEvent e) {}
    public void mousePressed  (MouseEvent e) {}
    public void mouseReleased (MouseEvent e) {
        Component cmpTemp = e.getComponent();
        if (cmpTemp == null)
            return; //report error

        int iXPos     = e.getX();
        int iYPos     = e.getY();
        JTree tmpTree = (JTree) cmpTemp;
        int iRow      = tmpTree.getRowForLocation (iXPos, iYPos);
        
        if (iRow == -1)
            return; //report error
        
//        if (!e.isPopupTrigger())
//            return;

        TreePath selPath = tmpTree.getPathForLocation (iXPos, iYPos);

        Object [] oTmpPath = selPath.getPath();
        int iTmpPathLen = oTmpPath.length;
        if (iTmpPathLen <= 0) {
            return; // report error
        }
        Object oPopup = this.getTreeObject (oTmpPath); //((Host) treeObject).getTreeObject (oTmpPath);
        if (oPopup == null) {
            return; // report error
        }
//            String sClassName = oPopup.getClass().getName();

        this.getClassPopupOption (oPopup, iXPos, iYPos);
    }
    public void mouseEntered  (MouseEvent e) {}
    public void mouseExited   (MouseEvent e) {} 
    
    /** Creates new form BeanForm */
    public TreeTab() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

  /**
   * 
   */
  abstract Object getTreeObject (Object [] objectPath);
  /**
   *
   */
   public JTree getTree () {return visibleTree;}
   /**
    * 
    */
   abstract mainScreen getMainScreen (Object treeObject);
   /**
    * 
    */
   abstract DefaultMutableTreeNode getMutableTreeNode (Object treeObject);
   /**
    * 
    */
   abstract void getClassPopupOption (Object oPopup, int iXPos, int iYPos);
}
